package de.windeln.marketing;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {

	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

	/**
	 * Simply selects the home view to render by returning its name.
	 */
	// , consumes="text/html;charset=utf-8"
	@RequestMapping(value = "/*", method = RequestMethod.GET, produces = "text/html")
	public String home(HttpServletRequest request, ModelMap model) {
		model.put("home", "titel home");
		StringBuffer requestURL = request.getRequestURL();
		if (requestURL.lastIndexOf(".") != -1) {
			int lastSlash = requestURL.lastIndexOf("/");
//			System.out.println("lastSlash: " + lastSlash);
			int lastPoint = requestURL.lastIndexOf(".html");
//			System.out.println("lastPoint: " + lastPoint);
			model.put("requestedPage", requestURL.substring(lastSlash + 1, lastPoint).concat(".html"));
		}else{
			model.put("requestedPage", "login.html");
		}
		// request..put("url", request.getAttribute("CURRENT_URL"));
		return "home";// redirect:/home.html;
	}

}
